/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.braincasedesigns.roller.parser.model;

/**
 *
 * @author jcampbel
 */
public class RollDescription {

    private int repeat = 1; //Default is to roll it once.
    private int numberOfDice = 1;
    private String faces;
    private Modifier modifier;

    public RollDescription() {
    }

    public String getFaces() {
        return faces;
    }

    public void setFaces(String faces) {
        this.faces = faces;
    }

    public Modifier getModifier() {
        return modifier;
    }

    public void setModifier(Modifier modifier) {
        this.modifier = modifier;
    }

    public int getNumberOfDice() {
        return numberOfDice;
    }

    public void setNumberOfDice(int numberOfDice) {
        this.numberOfDice = numberOfDice;
    }

    public int getRepeat() {
        return repeat;
    }

    public void setRepeat(int repeat) {
        this.repeat = repeat;
    }

    public void load(RollDescription roll) {
        this.setFaces(roll.getFaces());
        this.setModifier(roll.getModifier());
        this.setNumberOfDice(roll.getNumberOfDice());
        this.setRepeat(roll.getRepeat());
    }

    public RollDescription getRoll() {
        return this;
    }

    public RollDescription(int repeat, int dice, String faces, Modifier modifier) {
        this.repeat = repeat;
        this.numberOfDice = dice;
        this.faces = faces;
        this.modifier = modifier;
    }

    public String toString() {
        StringBuilder buf = new StringBuilder();
        buf.append("Roll ");

        buf.append(numberOfDice);

        buf.append(" d");
        buf.append(faces);

        if (modifier != null) {
            buf.append(" with ");
            buf.append(modifier.toString());
        }
        switch (repeat) {
            case 0:
                buf.append(" never.");
                break;
            case 1:
                buf.append(" one time.");
                break;
            default:
                buf.append(" ");
                buf.append(repeat);
                buf.append(" times.");

        }

        return buf.toString();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final RollDescription other = (RollDescription) obj;
        if (this.repeat != other.repeat) {
            return false;
        }
        if (this.numberOfDice != other.numberOfDice) {
            return false;
        }
        if (this.faces != other.faces && (this.faces == null || !this.faces.equals(other.faces))) {
            return false;
        }
        if (this.modifier != other.modifier && (this.modifier == null || !this.modifier.equals(other.modifier))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 67 * hash + this.repeat;
        hash = 67 * hash + this.numberOfDice;
        hash = 67 * hash + (this.faces != null ? this.faces.hashCode() : 0);
        hash = 67 * hash + (this.modifier != null ? this.modifier.hashCode() : 0);
        return hash;
    }
}
